package com.zyh.calendar;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CalendarDemo1 {
    public static void main(String[] args) throws ParseException {
        /*
        将字符串"1991-10-24"日期时间字符串增加1年之后在输出："1992年10月24日"
         */
        String date="1991-10-24";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = sdf.parse(date);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(parse);
        calendar.add(Calendar.YEAR,1);
//        System.out.println("calendar = " + calendar);
        Date time = calendar.getTime();
        String format = sdf.format(time);
        System.out.println("format = " + format);
    }

    public static void main1(String[] args) {
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.HOUR));
        calendar.add(Calendar.YEAR,2);
        System.out.println("calendar = " + calendar);
        Calendar calendar1 = Calendar.getInstance();
        Date time = calendar1.getTime();
        System.out.println("time = " + time);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(Calendar.YEAR,2002);
        System.out.println("calendar2 = " + calendar2);
        calendar2.setTime(new Date(0L));
        System.out.println("calendar2 = " + calendar2);
    }
}
